<?php
// No direct access
defined('_JEXEC') or die;

class PricerProductsHelper {

	public static $extension = 'com_pricerproducts';

	public static function addSubmenu($vName) {
		JSubMenuHelper::addEntry(
			JText::_('COM_PRICER_SUBMENU_PRODUCTS'),
			'index.php?option=com_pricerproducts&view=products',
			$vName == 'products');
		JSubMenuHelper::addEntry(
			JText::_('COM_PRICER_SUBMENU_CATEGORIES'),
			'index.php?option=com_categories&extension=com_pricerproducts',
			$vName == 'categories');
		JSubMenuHelper::addEntry(
			JText::_('COM_PRICER_SUBMENU_VENDORS'),
			'index.php?option=com_pricerproducts&view=vendors',
			$vName == 'vendors');
		JSubMenuHelper::addEntry(
			JText::_('COM_PRICER_SUBMENU_PARAMETERS'),
			'index.php?option=com_pricerproducts&view=parameters',
			$vName == 'parameters');

		JSubMenuHelper::addEntry(
			JText::_('COM_PRICER_SUBMENU_STOCKS'),
			'index.php?option=com_pricerproducts&view=stocks',
			$vName == 'stocks');
		if (('stocks' == $vName) or ('quantities' == $vName)) {
			JSubMenuHelper::addEntry(
				JText::_('COM_PRICER_SUBMENU_QUANTITIES'),
				'index.php?option=com_pricerproducts&view=quantities',
				$vName == 'quantities');
		}

		JSubMenuHelper::addEntry(
			JText::_('COM_PRICER_SUBMENU_PRICES'),
			'index.php?option=com_pricerproducts&view=prices',
			$vName == 'prices');

		if (('prices' == $vName) or ('pricetypes' == $vName)) {
			JSubMenuHelper::addEntry(
				JText::_('COM_PRICER_SUBMENU_PRICE_TYPES'),
				'index.php?option=com_pricerproducts&view=pricetypes',
				$vName == 'pricetypes');
		}

		JSubMenuHelper::addEntry(
			JText::_('COM_PRICER_SUBMENU_CURRENCIES'),
			'index.php?option=com_pricerproducts&view=currencies',
			$vName == 'currencies');
		if (('currencies' == $vName) or ('currencyrates' == $vName)){
			JSubMenuHelper::addEntry(
				JText::_('COM_PRICER_SUBMENU_CURRENCY_RATES'),
				'index.php?option=com_pricerproducts&view=currencyrates',
				$vName == 'currencyrates');
		}
	}

	public static function getActions($categoryId = 0, $id = 0) {

		// Инициализируем переменные
		$user	= JFactory::getUser();
		$result	= new JObject;

		if (empty($id) && empty($categoryId)) {
			$assetName = 'com_pricerproducts';
		}

		elseif (empty($id)) {
			$assetName = 'com_pricerproducts.category.'.(int) $categoryId;
		}

		else {
			$assetName = 'com_pricerproducts.product.'.(int) $id;
		}

		$actions = array(
			'core.admin', 'core.manage', 'core.create', 'core.edit', 'core.edit.own', 'core.edit.state', 'core.delete'
		);

		foreach ($actions as $action) {
			$result->set($action,	$user->authorise($action, $assetName));
		}

		return $result;
	}
}
